﻿using Sidvall.AuthorizationManager.Data;
using Sidvall.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Sidvall.AuthorizationManager.UI.Entities
{
	public sealed partial class ActionOptionCollection
	{
		#region Public Members

		#region Add

		public void Add(string name)
		{
			var item = new ActionOption()
			{
				Name = name,
			};
			Add(item);
		}

		#endregion
		#region AddRange

		public void AddRange(IEnumerable<string> names)
		{
			if (names == null)
				return;
			foreach (var name in names)
				Add(name);
		}

		#endregion

		#region NewResourceActionOptions

		public static ActionOptionCollection NewResourceActionOptions()
		{
			var items = new ActionOptionCollection();
			items.Add(Sidvall.Security.Operations.GetOperations(Sidvall.Security.OperationTypes.GetGroup).JoinToString(AuthorizationScopeItemManager.ActionSeparator + " "));
			items.Add(Sidvall.Security.Operations.GetOperations(Sidvall.Security.OperationTypes.ItemGroup).JoinToString(AuthorizationScopeItemManager.ActionSeparator + " "));
			var orderedOperations = (from o in Sidvall.Security.Operations.GetOperations()
									 orderby o
									 select o);
			items.AddRange(orderedOperations);
			return items;
		}

		#endregion
		#region NewResourceItemActionOptions

		public static ActionOptionCollection NewResourceItemActionOptions()
		{
			var items = new ActionOptionCollection();
			items.Add(Sidvall.Security.Operations.GetOperations(Sidvall.Security.OperationTypes.ItemGroup).JoinToString(AuthorizationScopeItemManager.ActionSeparator + " "));
			var orderedOperations = (from o in Sidvall.Security.Operations.GetOperations(Sidvall.Security.OperationTypes.ItemGroup)
									 orderby o
									 select o);
			items.AddRange(orderedOperations);
			return items;
		}

		#endregion

		#endregion
	}
}